package com.hydra.base.utils;

import com.hydra.base.error.ValidateException;

/**
 * 通用工具类
 * @Author Hydra
 * @Date 2022/5/27 11:35
 */
public class CommonUtil {

    /**判断对象为空则抛出校验异常*/
    public static <T> T requireNonNull(T obj, String name) {
        return requireNonNull(obj, name, "不能为空！");
    }
    /**判断对象为空则抛出校验异常*/
    public static <T> T requireNonNull(T obj, String name, String message) {
        String errMessage = name + message;
        if (obj == null){
            throw new ValidateException(errMessage);
        }
        if(obj instanceof String && StringUtil.isBlank(obj.toString())){
            throw new ValidateException(errMessage);
        }
        return obj;
    }

}
